 /*******************************************************************************
 * CLASS		Mode
 * AUTHOR		John Paul Swaynos
 * DESCRIPTION
 * This is the C++ code for the wrapper class that basically contains the handle
 * for the windows of each mode of the application.
 ******************************************************************************/
#include "Mode.h"
Mode::Mode(int whichWindow)  {
	// check to see if whichWindow is in bounds
	if (whichWindow <= 3 && whichWindow > 0) {
		HINSTANCE hInstance = GetModuleHandle(NULL);
		szAppName1 = "FreePhotoBooth - Easy Mode";
		szAppName2 = "FreePhotoBooth - Photo Mode";
		szAppName3 = "FreePhotoBooth - Printer Mode";
		wc = createMyWindowClass(whichWindow);
		RegisterClass(&wc);
		switch(whichWindow) {
			HWND camhwnd;
			case EASYMODE:
				numOfShots = 0;
				shotsTaken = 0;
				hwnd = CreateWindow(szAppName1,szAppName1,WS_OVERLAPPED|WS_CAPTION|WS_SYSMENU|WS_MINIMIZEBOX,CW_USEDEFAULT,CW_USEDEFAULT,640,700,0,0,hInstance,0);
				camhwnd = capCreateCaptureWindow("camera window", WS_CHILD , 25, 85, 580, 435, hwnd, 0);
				SendMessage(camhwnd,WM_CAP_DRIVER_CONNECT,0,0);
				SendMessage(camhwnd,WM_CAP_DLG_VIDEOSOURCE,0,0);
				this->camhwnd = camhwnd;
				break;
			case PHOTOMODE:
				shotsTaken = 0;
				numOfShots = NULL;
				hwnd = CreateWindow(szAppName2,szAppName2,WS_OVERLAPPED|WS_CAPTION|WS_SYSMENU|WS_MINIMIZEBOX,CW_USEDEFAULT,CW_USEDEFAULT,640,700,0,0,hInstance,0);
				camhwnd = capCreateCaptureWindow("camera window", WS_CHILD , 25, 85, 580, 435, hwnd, 0);
				this->camhwnd = camhwnd;
				break;
			case PRINTERMODE:
				numOfShots = NULL;
				hwnd = CreateWindow(szAppName3,szAppName3,WS_OVERLAPPED|WS_CAPTION|WS_SYSMENU|WS_MINIMIZEBOX,CW_USEDEFAULT,CW_USEDEFAULT,640,700,0,0,hInstance,0);
				break;
		}
	}
	else {
		OutputDebugString("The integer whichWindow entered into the Mode constructor is not within bounds\nwhichWindow: ");
		char buffer[10] = ""; // The largest 32-bit signed int possible is 10 digits in base 10
		itoa(whichWindow, buffer, 10);
		OutputDebugString(buffer);
	}
}
HWND Mode::getWindow() {
	return this->hwnd;
}
HWND Mode::getCapWindow() {
	return this->camhwnd;
}
WNDCLASS Mode::createMyWindowClass(int whichWindow) {
	HINSTANCE hInstance = GetModuleHandle(NULL);
	WNDCLASS wc;
	char * szAppName;
	switch(whichWindow) {
		case EASYMODE:
			szAppName = szAppName1;
			wc.lpfnWndProc = EasyModeProc;
			break;
		case PHOTOMODE:
			szAppName = szAppName2;
			wc.lpfnWndProc = PhotoModeProc;
			break;
		case PRINTERMODE:
			szAppName = szAppName3;
			wc.lpfnWndProc = PrinterModeProc;
			break;
	}
    wc.style = CS_HREDRAW|CS_VREDRAW;
    wc.cbClsExtra = 0;
    wc.cbWndExtra = 0;
    wc.hInstance = hInstance;
    wc.hIcon = LoadIcon(GetModuleHandle(NULL), IDI_APPLICATION);
    wc.hCursor = LoadCursor (NULL, IDC_ARROW);
    wc.hbrBackground = (HBRUSH) (COLOR_WINDOW);
    wc.lpszMenuName = NULL;
    wc.lpszClassName = szAppName;
	return wc;
}
void Mode::setNumOfShots(int numOfShots) {
	this->numOfShots = numOfShots;
}
int Mode::getNumOfShots() {
	return numOfShots;
}
void Mode::setShotsTaken(int shotsTaken) {
	this->shotsTaken = shotsTaken;
}
int Mode::getShotsTaken() {
	return shotsTaken;
}